import { Modal, Form, Input, Checkbox, Button } from "antd";
import { LockOutlined, UserOutlined } from "@ant-design/icons";
import request from "@/service/request";
import { useStore } from "@/store/index";
interface IProps {
  isShow: boolean;
  onClose: () => void;
}

type FieldType = {
  username?: string;
  password?: string;
};

const Login = (props: IProps) => {
  const store = useStore();
  const onFinish = async (values: any) => {
    console.log("Success:", values);
    const res = await request.post("/api/login", values);
    console.log(res);
    store.user.setUserInfo({
      userId: 1,
      nickname: "123",
    });
    console.log(store)
  };
  const { isShow = false, onClose } = props;
  return (
    isShow && (
      <Modal title="登录" width={450} open={isShow} footer onCancel={onClose}>
        <Form
          name="normal_login"
          className="mt-10 login-form"
          initialValues={{ remember: true }}
          onFinish={onFinish}
        >
          <Form.Item
            name="username"
            rules={[{ required: true, message: "请输入用户名!" }]}
          >
            <Input
              prefix={<UserOutlined className="site-form-item-icon" />}
              placeholder="Username"
            />
          </Form.Item>
          <Form.Item
            name="password"
            rules={[{ required: true, message: "请输入密码!" }]}
          >
            <Input
              prefix={<LockOutlined className="site-form-item-icon" />}
              type="password"
              placeholder="Password"
            />
          </Form.Item>
          <Form.Item>
            <Form.Item name="remember" valuePropName="checked" noStyle>
              <Checkbox>记住我</Checkbox>
            </Form.Item>

            <a className="float-right" href="">
              忘记密码
            </a>
          </Form.Item>

          <Form.Item>
            <Button
              type="primary"
              htmlType="submit"
              className="login-form-button"
              block
            >
              登录
            </Button>
            <div className="mt-1">
              或者 <a href="">注册</a>
            </div>
          </Form.Item>
        </Form>
      </Modal>
    )
  );
};

export default Login;
